<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>收款单管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">

		$(document).ready(function() {
			$("#inputForm").validate({
				submitHandler: function(form){
					jp.loading();
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
	        $('#billDate').datetimepicker({
				 format: "YYYY-MM-DD HH:mm:ss"
		    });
            //当结算日期为空时，赋值当前时间
            if($("#dd").val()==""){
                document.getElementById("dd").value = getNowFormatDate();
            }
            //初始状态默认为已输入
            if($("#status").val()==""){
                $("#status").val(0);
            }
			//获取发票主表的合同签约方赋值给收款单的合同签约方
            if($("#invoiceObj").val()){
                $("#payerNameName").val($("#invoiceObj").val());
            }
            //获取结算单主表的结算方赋值给收款单的合同签约方
            if ($("#feePayableName").val()) {
                $("#payerNameName").val($("#feePayableName").val());
            }
		});
        <%--给日期赋初始值--%>
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var minute = date.getMinutes();
            if (minute >= 0 && minute <= 9) {
                minute = "0" + minute;
            }
            var seconds = date.getSeconds();
            if (seconds >= 0 && seconds <= 9) {
                seconds = "0" + seconds;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + date.getHours() + seperator2 + minute + seperator2 + seconds;
            return currentdate;
        }
        //引入发票明细按钮
        function model(){
            all_ajax();
		}
        //弹出框提取数据ajax
        function all_ajax(){
            //调用查询结算单id的方法
            var billIds = searchBillId();
            var balance = $("#balance").val().trim();
            $.ajax({
                url : "${ctx}/fee/bill/findOpenInvoiceList",
                data:{"status":3,"clearUnit": balance,"billIds":billIds},
                success: function(data) {
                    $("#openInvoiceDetailLists").empty();
                    console.log(data);
                    $.each(data,function(index,item) {
                        var addTr = $("<tr id='"+item.id+"'></tr>");
                        addTr.appendTo("#openInvoiceDetailLists");
                        var td = ("<td>"+"<input id='"+item.id+"' value='"+item.id+"' type='checkbox' class='i-checks'>"+"</td>");
                        addTr.append(td);
                        if(item.status==1){
                            addTr.append($("<td id='status_"+item.id+"'>"+"</td>").text("已确认"));
                        }else{
                            addTr.append($("<td id='status_"+item.id+"'>"+"</td>").text("部分核销"));
                        }
                        addTr.append($('<td></td>').text(item.invoiceNo));
                        addTr.append($('<td></td>').text(item.invoiceDate));
                        addTr.append($("<td id='payer_"+item.id+"'>"+"</td>").text(item.invoiceObj));
                        addTr.append($('<td></td>').text(item.invoiceMoney));
                        addTr.append($('<td></td>').text(item.remarks));
                    })
                },
                error : function(data){
                    alert("操作失败!");
                }
            });
        }
        //获取收款单主表id
        function searchBillId(){
            var billId = $("#billId").val();
            var tempRece="";
            <%--同步请求--%>
            $.ajax({
                url : "${ctx}/fee/bill/findBillReceiveDetailByBillId",
                async: false,
                data : {		 //参数值
                    "id" :billId
                },
                type:"post",
                success : function(data) {
                    console.log(data);
                    $.each(data, function (index, term) {
                        tempRece += term.feeReceivables.id+",";
                    })
                    return tempRece;
                },
                error : function(data){
                    alert("操作失败!");
                }
            });
            return tempRece;
        }
        //获取引入发票弹出框上查询按钮
        function searchDetail() {
            //加载层-默认风格
            layer.load();
            //此处演示关闭
            setTimeout(function(){
                layer.closeAll('loading');
            },500);
            all_ajax();
            receivable_ajax();
        }

        //获取引入发票弹出框上重置按钮
        function reset(){//重置，页码清零
            $("#pageNo").val(0);
            $("#searchForm div.form-group input").val("");
            $("#searchForm div.form-group select").val("");
            //加载层-默认风格
            layer.load();
            //此处演示关闭
            setTimeout(function(){
                layer.closeAll('loading');
            },500);
            all_ajax();
            receivable_ajax();
            return false;
        }
        //已输入状态下删除一条明细记录【从付款单明细表中删除】
        function deletes(id){
            if (confirm("确定要删除吗？")) {
                window.location.href = "${ctx}/fee/bill/removeFeeBillDetail?id=" + id;
            }
        }
        //点击确认按钮将已输入状态修改为已确认状态
        function verify(id,type){
            window.location.href="${ctx}/fee/bill/updateStatus?id="+id+"&type="+type;
        }
        //不走后台，删除已经引入的明细
        function deleteInPage(id,inputId) {
            if (confirm("确定要删除吗？")) {
                //获取原来的收款金额
                var billMoney = $("#money").val() * 1;
                //获取本次核销金额
                var theVcaMoney = $("#" + inputId + "_theVcaMoney").val() * 1;
                //给付款单主表的付款金额重新赋值
                $("#money").val(billMoney - theVcaMoney);
                //alert("付款金额:"+payMoney+",本次核销金额:"+theVcaMoney);
                $("#detailTbody tr").each(function () {	//循环获取tr
                    var trId = $(this).attr("id");
                    if (trId == id) {
                        //获得页面原来的ids
                        var str = $("#ids").val();
                        var _str = str.trim().split(",");
                        str = "";
                        for (var i = 0; i < _str.length; i++) {
                            if (!(_str[i].indexOf(id) < 0)) {
                                //ids删除id,ids中原来包含的id置为空字符串
                                _str[i] = "";
                            }
                            //重新追加ids的值
                            str += _str[i] + ",";
                        }
                        //ids重新赋值
                        $("#ids").val(str);
                        //tbody删除id= 传入id的一行数据
                        $(this).remove();
                    }
                })
            }
        }
        //获取本次开票金额和应付账款id
        function inputBlur(){
            var countMoney = 0 *1;
            var tempId = "";
            var inputId = "";
            $("#contentTable tr:gt(0)").each(function(i){
                $(this).children("td").each(function(j){
                    if($(this).attr("class") == "coun"){
                        inputId = $(this).attr("name")+"_theVcaMoney";
                        var tempMoney = $("#"+inputId).val();
                        if(isNaN(tempMoney)){
                            alert("请输入数字");
                            $("#"+inputId).val(null);
                            return;
                        }
                        if(tempMoney >= 0){
                            //获得开票金额
                            var voiceObj = $(this).attr("name")+"_invoiceMoney";
                            var voiceMoney = $("#"+voiceObj).text() * 1;
                            //获取已核销金额
                            var vcaObj = $(this).attr("name")+"_vcaMoney";
                            var vcaMoney = $("#"+vcaObj).text() * 1;
                            //alert("开票金额"+voiceMoney+"，已核销金额"+vcaMoney+",本次核销金额"+tempMoney);
                            //比较    本次核销金额    是否大于  开票金额-已核销金额【如果大于，返回；如果小于，继续执行】
                            if(tempMoney > (voiceMoney-vcaMoney)){
                                alert("本次核销金额不得大于未核销金额!");
                                $("#"+inputId).val(null);
                                return;
                            }
                            countMoney += tempMoney * 1;
                            tempId += $(this).attr("name")+"_"+tempMoney;
                            tempId += ",";
                        }else{
                            alert("核销金额不能小于零");
                            $("#"+inputId).val(null);
                            return;
                        }
                    }
                });
            });
            //获取收款金额
            $("#money").val(countMoney);
            var values = $("#ids").val();
            values = tempId;
            $("#ids").val(values);
        }
        //获得所有选中的复选框的id
        function getCheckBox(){
            var boxs = "";		//设置变量，用于接收选中的复选框
            $("input:checkbox").each(function() {
                //判断复选框是否被选中
                if ($(this).is(':checked') && $(this).attr("id") != "allCheckBox") {
                    boxs += $(this).val();
                    boxs += ",";	//复选框的val()id集合以逗号分割
                }
            });
            return boxs;
        }
        //引入发票模态框的确定按钮
        function detail(){
            var tempIds = getCheckBox();
            var tempStr = tempIds.split(",");
            var ids = "";	//获取选中复选框的id
            var sc = "";	//机构名称变量
            var textName = "";
            if(tempIds == null || tempIds == ""){
                alert("请至少选择一条数据");
                return;
            }
            for(var i=0;i<tempStr.length;i++){
                if(!tempStr[i]) continue;
                tempSc = $("#payer_"+tempStr[i]).text().trim();
                if(!sc){
                    sc = tempSc;	//第一个元素赋值到sc
                }else if(sc != tempSc){//上一个元素sc与本次循环的值不相等，不是同一个机构
                    alert("请选择相同合同签约方!");
                    return;
                }
                if($("#status_"+tempStr[i]).text()){
                    var text = $("#status_"+tempStr[i]).text().trim();
                    if(text == "已确认" || text == "部分核销"){
                        //状态为已确认和部分开票才能进行开票操作
                        textName = !textName ? text : textName;
                        if(text == textName){
                            ids += tempStr[i]+",";
                        }else{
                            alert("请选择相同状态的发票!");
                            return;
                        }
                    }
                }else return ;
            }
            $('#myModal').modal('hide');
            $(".modal-backdrop").removeClass('in');
            layer.load();
            var target = "${target}";
            //window.location.href = "${ctx}/fee/feeOpenInvoice/addFeeBill?ids="+ids+"&target="+target;
            $.ajax({
                url : "${ctx}/fee/bill/addFeeBill",
                data : {		 //参数值
                    "ids" :ids,
                    "target":target
                },
                type:"post",
                success : function(data) {
                    //获取收款单主表应经存在的结算方
                    var payerName = $("#payerNameName").val();
                    if(data){
                        var invoiceObj = "";
                        var list = eval(data);
                        var ids =$("#ids");
                        $.each(list, function (index, term) {
                            //获取引入发票明细的结算方
                            var invoiceObj = term.feeOpenInvoice.invoiceObj;
                            //判断收款单主表的结算方不为空并和引入明细时的结算方比较是否相等
                            if (payerName && payerName != invoiceObj) {
                                alert("引入的结算方与收款单的结算方不一致！");
                                return;
                            } else {
                                var addTr = $("<tr id='" + term.feeOpenInvoice.id + "'></tr>");
                                addTr.appendTo("#detailTbody");
                                var td = ("<td>" + "<input id='" + term.id + "'  type='checkbox' class='i-checks'>" + "</td>");
                                addTr.append(td);
                                addTr.append($('<td></td>').text(term.feeOpenInvoice.entityNo));
                                addTr.append($("<td id='" + term.feeOpenInvoice.id + "_" + term.id + "_invoiceMoney'>" + "</td>").text(term.invMoney));
                                addTr.append($("<td id='" + term.feeOpenInvoice.id + "_" + term.id + "_vcaMoney'>" + "</td>").text(term.vcaMoney));
                                addTr.append("<td  class='coun' name='" + term.feeOpenInvoice.id + "_" + term.id + "'>" + "<input type='text' id='" + term.feeOpenInvoice.id + "_" + term.id + "_theVcaMoney' onchange=\"inputBlur()\"  class='form-control number required' value=''/>" + "</td>");
                                addTr.append($('<td></td>').text(term.remarks));
                                addTr.append("<td><a href='#' onclick=\"jp.openDialogView('查看结算单明细', '${ctx}/fee/openInvoice/form?id=" + term.feeOpenInvoice.id + "','800px', '500px')\" class='btn btn-info btn-xs' ><i class='fa fa-search-plus'></i> 查看</a>"
                                    + "&nbsp;<input onclick=\"deleteInPage('" + term.feeOpenInvoice.id + "','" + term.feeOpenInvoice.id + "_" + term.id + "')\"  type='button' value='删除' class='btn btn-danger btn-xs'>" + "</td>");
                                var tempId = ids.val();
                                tempId += term.feeOpenInvoice.id;
                                tempId += ",";
                                ids.val(tempId);
                                //设置收款单主表的结算方
                                $("#payerNameName").val(invoiceObj);
                            }
                        })
                        layer.closeAll('loading');
                    }
                },
                error : function(data){
                    alert("操作失败!");
                    layer.closeAll('loading');
                }
            });
		}
        //引入结算单明细按钮
		function btn_receive(){
            receivable_ajax();
		}
        //结算单弹出框
        function receivable_ajax(){
            var balance_payable = $("#balance_payable").val().trim();
            $.ajax({
                url : "${ctx}/fee/bill/findAllFeeReceivables",
                data:{"status":1 , "clearUnit": balance_payable},
                success: function(data) {
                    console.log(data);
                    $("#receiveLists").empty();
                    var list = eval(data);
                    $.each(data,function(index,item) {
                        var addTr = $("<tr id='"+item.id+"'></tr>");
                        addTr.appendTo("#receiveLists");
                        var td = ("<td>"+"<input id='"+item.id+"' value='"+item.id+"' type='checkbox' class='i-checks'>"+"</td>");
                        addTr.append(td);
                        if(item.status==1){
                            addTr.append($("<td id='status_"+item.id+"'>"+"</td>").text("已确认"));
                        }else{
                            addTr.append($("<td id='status_"+item.id+"'>"+"</td>").text("部分核销"));
                        }
                        addTr.append($('<td></td>').text(item.clearingNo));
                        addTr.append($('<td></td>').text(item.busyDate));
                        addTr.append($("<td id='payer_"+item.id+"'>"+"</td>").text(item.payerName.name));
                        addTr.append($('<td></td>').text(item.payMoney));
                        addTr.append($('<td></td>').text(item.remarks));
                    })
                },
                error : function(data){
                    alert("操作失败!");
                }
            });
        }
        //获得所有选中结算单的复选框的id
        function getReceivableCheckBox(){
            var boxs = "";		//设置变量，用于接收选中的复选框
            $("input:checkbox").each(function() {
                //判断复选框是否被选中
                if ($(this).is(':checked') && $(this).attr("id") != "all_payable") {
                    boxs += $(this).val();
                    boxs += ",";	//复选框的val()id集合以逗号分割
                }
            });
            return boxs;
        }
        <%--不走后台，删除已经引入结算单的明细--%>
        function deleteInPageRece(id, inputId) {
            if (confirm("确定要删除吗？")) {
                //获取原来的付款金额
                var payMoney = $("#money").val() * 1;
                //获取本次核销金额
                var theVcaMoney = $("#" + inputId + "_theVcaMoney").val() * 1;
                //给付款单主表的付款金额重新赋值
                $("#money").val(payMoney - theVcaMoney);
                //	alert("付款金额:"+payMoney+",本次核销金额:"+theVcaMoney);
                $("#payableDetailTbody tr").each(function () {
                    var trId = $(this).attr("id");
                    if (trId == id) {
                        //获得页面原来的ids
                        var str = $("#ids_payable").val();
                        var _str = str.trim().split(",");
                        str = "";
                        for (var i = 0; i < _str.length; i++) {
                            if(!(_str[i].indexOf(id) < 0) ) {
                                //ids删除id,ids中原来包含的id置为空字符串
                                _str[i] = "";
                            }
                            //重新追加ids的值
                            str += _str[i] + ",";
                        }
                        //ids重新赋值
                        $("#ids_payable").val(str);
                        //tbody删除id= 传入id的一行数据
                        $(this).remove();
                    }
                })
            }
        }
        //删除资表记录【从付款单--结算单明细表中删除】
        function deleteFeeBillReceDetail(id) {
            if (confirm("确定要删除吗？")) {
                window.location.href = "${ctx}/fee/bill/removebillReceDetail?id=" + id;
            }
        }
        <%--获取引入结算单的本次核销金额和应付账款id--%>
        function inputBlurRece() {
            var countMoney = 0 * 1;
            var tempId = "";
            var inputId="";
            $("#contentTable_payable tr:gt(0)").each(function (i) {
                $(this).children("td").each(function (j) {
                    if ($(this).attr("class") == "coun") {
                        inputId = $(this).attr("name") + "_theVcaMoney";
                        var tempMoney = $("#" + inputId).val();
                        if (isNaN(tempMoney)) {
                            alert("请输入数字");
                            $("#" + inputId).val(null);
                            return;
                        }
                        if (tempMoney >= 0) {
                            //获得开票金额
                            var voiceObj = $(this).attr("name") + "_invoiceMoney";
                            var voiceMoney = $("#" + voiceObj).text() * 1;
                            //获取已核销金额
                            var vcaObj = $(this).attr("name") + "_vcaMoney";
                            var vcaMoney = $("#" + vcaObj).text() * 1;
                            //alert("开票金额"+voiceMoney+"，已核销金额"+vcaMoney+",本次核销金额"+tempMoney);
                            //比较    本次核销金额    是否大于  开票金额-本次核销金额【如果大于，返回；如果小于，继续执行】
                            if (tempMoney > (voiceMoney - vcaMoney)) {
                                alert("本次核销金额不得大于未核销金额!");
                                $("#" + inputId).val(null);
                                return;
                            }
                            countMoney += tempMoney * 1;
                            tempId += $(this).attr("name") + "_" + tempMoney;
                            tempId += ",";
                        } else {
                            alert("核销金额不能小于零");
                            $("#" + inputId).val(null);
                            return;
                        }
                    }
                });
            });
            $("#money").val(countMoney);
            var values = $("#ids_payable").val();
            values = tempId;
            $("#ids_payable").val(values);
        }
        //引入结算单模态框的确定按钮
        function sure_payable(){
            var tempIds = getReceivableCheckBox();
            var tempStr = tempIds.split(",");
            var ids = "";	//获取选中复选框的id
            var sc = "1";	//机构名称变量
            var textName = "";
            if (tempIds == null || tempIds == "") {
                alert("请至少选择一条数据");
                return;
            }
            for (var i = 0; i < (tempStr.length - 1); i++) {
                if (!tempStr[i]) continue;
                var tempSc = $("#payer_" + tempStr[i]).text().trim();
                if (sc == "1") {
                    sc = tempSc;	//第一个元素赋值到sc
                } else if (sc != tempSc) {//上一个元素sc与本次循环的值不相等，不是同一个机构
                    layer.alert("请选择相同的结算方!");
                    return;
                }
                if ($("#status_" + tempStr[i]).text()) {
                    var text = $("#status_" + tempStr[i]).text().trim();
                    if (text == "已确认" || text == "部分核销") {
                        //状态为已确认
                        textName = !textName ? text : textName;
                        if (text == textName) {
                            ids += tempStr[i] + ",";

                        }else {
                            alert("请选择相同状态的发票!");
                            return;
                        }
                    } else return;
                }
            }
            $('#modal_payable').modal('hide');
            $(".modal-backdrop").removeClass('in');
            $(".payable").addClass("active");
            $(".payInvoice").removeClass("active");
            $("#tab-2").addClass("active");
            $("#tab-1").removeClass("active");
            layer.load();
            //拼接表格数据
            $.ajax({
                url: "${ctx}/fee/bill/addFeeReceivablesDetails",
                data: {		 //参数值
                    "ids": ids,
                },
                type: "post",
                success: function (data) {
                    //获取付款单主表应经存在的结算方
                    var payee = $("#payerNameName").val();
                    if (data) {
                        var feePayableName = "";
                        var ids = $("#ids_payable");
                        var list = eval(data);
                        $.each(list, function (index, term) {
                            //获取引入结算单明细的结算方
                            feePayableName = term.payerName.name;
                            //判断付款单主表的结算方不为空并和引入明细时的结算方比较是否相等
                            if (payee && payee != feePayableName) {
                                alert("引入的结算方与付款单的结算方不一致！");
                                return;
                            }else{
                                var addTr = $("<tr id='" + term.id + "'></tr>");
                                addTr.appendTo("#payableDetailTbody");
                                var td = ("<td>" + "<input id='" + term.id + "'  type='checkbox' class='i-checks'>" + "</td>");
                                addTr.append(td);
                                addTr.append($('<td></td>').text(term.clearingNo));
                                addTr.append($("<td></td>").text(term.busyDate));
                                addTr.append($("<td></td>").text(term.payerName.name));
                                addTr.append($("<td id='" +term.id+ "_invoiceMoney'>"+"</td>").text(term.payMoney));
                                addTr.append($("<td id='"+term.id+"_vcaMoney'>"+"</td>").text(term.vcaMoney));
                                addTr.append("<td  class='coun' name='"+term.id+"'>"+"<input type='text' id='"+term.id+"_theVcaMoney' onchange=\"inputBlurRece()\"  class='form-control required' value=''/>"+"</td>");
                                addTr.append($('<td></td>').text(term.remarks));
                                addTr.append("<td><a href='#' onclick=\"jp.openDialogView('查看结算单明细', '${ctx}/fee/receivables/form?different=invoicePage&id=" + term.id + "','800px', '500px')\" class='btn btn-info btn-xs' ><i class='fa fa-search-plus'></i> 查看</a>"
                                    + "&nbsp;<input onclick=\"deleteInPageRece('" + term.id + "','" + term.id + "')\"  type='button' value='删除' class='btn btn-danger btn-xs'>" + "</td>");
                                var tempId = ids.val();
                                tempId += term.id;
                                tempId += ",";
                                ids.val(tempId);
                                //设置收款单主表的结算方
                                $("#payerNameName").val(feePayableName);
                            }
                        })
                        layer.closeAll('loading');
                    }
                },
                error: function (data) {
                    alert("操作失败!");
                    layer.closeAll('loading');
                }
            });
		}
	</script>
</head>
<body>
<div class="wrapper wrapper-content">				
<div class="row">
	<div class="col-md-12">
	<div class="panel panel-primary">
		<c:if test="${type ne 1}"><%--type=1是来自应收结算单list页面上的开票按钮--%>
				<div class="panel-heading">
					<h3 class="panel-title">
						<a class="panelButton" href="${ctx}/fee/bill"><i class="ti-angle-left"></i> 返回</a>
					</h3>
				</div>
		</c:if>
		<c:if test="${type eq 1}"><%--type=1是来自应收结算单list页面上的开票按钮--%>
			<div class="panel-heading">
				<h3 class="panel-title">
					<a class="panelButton" href="${ctx}/fee/openInvoice"><i class="ti-angle-left"></i> 返回</a>
				</h3>
			</div>
		</c:if>
		<c:if test="${type ne 1}"><%--type=1是来自应收结算单list页面上的开票按钮--%>
			<br>
			<c:if test="${bill.id eq null or bill.status eq 0 or bill.status eq 2}">
				<button class="btn btn-primary btn-sm fl" data-toggle="modal" data-target="#myModal" onclick="model()">引入发票</button>
			</c:if>
			<%--添加引入结算单按钮--%>
			<c:if test="${bill.id eq null or bill.status eq 0 or bill.status eq 2}">
				<button class="btn btn-primary btn-sm fl" data-toggle="modal" data-target="#modal_payable" onclick="btn_receive()">引入结算单
				</button>
			</c:if>
		</c:if>
		<c:if test="${bill.id ne null and bill.status eq 0}">
			<a href="#" onclick="verify('${bill.id}','form')" class="btn btn-success btn-sm"> 确认</a>
		</c:if>
		<div class="panel-body">
		<form:form id="inputForm" modelAttribute="bill" action="${ctx}/fee/bill/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
			<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
				<tbody>
				<tr>
				<c:if test="${bill.billNo ne null}">
					<td class="width-12 active"><label class="pull-right"><font color="red">*</font>收款单号：</label></td>
					<td class="width-21">
						<form:input path="billNo" htmlEscape="false"    class="form-control required"/>
					</td>
				</c:if>
					<td class="width-12 active"><label class="pull-right"><font color="red">*</font>收款日期：</label></td>
					<td class="width-21">
						<div class='input-group form_datetime' id='billDate'>
							<input type='text' id="dd" name="billDate" class="form-control"  value="<fmt:formatDate value="${bill.billDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
							<span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
						</div>
					</td>
					<td class="width-12 active"><label class="pull-right">状态：</label></td>
					<td class="width-21">
						<form:select path="status" id="status" class="form-control required">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('bill_status')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
				</tr>
				<tr>
					<td class="width-12 active"><label class="pull-right"><font color="red">*</font>结算方：</label></td>
					<td class="width-21">
						<sys:gridselect url="${ctx}/fee/consignor/data" id="payerName" name="payerName.id" value="${bill.payerName.id}" labelName="payerName.name" labelValue="${bill.payerName.name}"
										title="选择结算方" cssClass="form-control required" fieldLabels="结算方" fieldKeys="name" searchLabels="结算方" searchKeys="name" ></sys:gridselect>
					</td>
					<td class="width-12 active"><label class="pull-right">收款金额：</label></td>
					<td class="width-21">
						<c:if test="${sign eq 'invoice'}">
							<input name="billMoney"  type="text" id="money" value="<fmt:formatNumber value="${bill.billMoney}" pattern="#.00"/>"readonly="true"  class="form-control  number"/>
						</c:if>
						<c:if test="${ids eq null}">
							<input name="billMoney" type="text" id="money" value="<fmt:formatNumber value="${bill.billMoney}" pattern="#.00"/>" readonly="true" class="form-control  number"/>
						</c:if>
					</td>
					<td class="width-12 active"><label class="pull-right"><font color="red">*</font>支付方式：</label></td>
					<td class="width-21">
						<form:select path="payMethod" class="form-control required">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('pay_method_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
				</tr>
				<tr>
					<td class="width-12 active"><label class="pull-right">备注信息：</label></td>
					<td class="width-21">
						<%--<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>--%>
						<form:input path="remarks" htmlEscape="false"    class="form-control "/>
					</td>

				</tr>
				</tbody>
			</table>
			<input type="hidden" id="ids" name="ids" value="${ids}"/>
			<input type="hidden" name="typeTarget" value="${target}" />
			<input type="hidden" id="ids_payable" name="ids_payable" value=""/>
			<!-- 收款单明细表 -->
			<div class="tabs-container tab-container">
				<ul class="nav nav-tabs nav-style">
					<li class="active payInvoice"><a data-toggle="tab" href="#tab-1" aria-expanded="true">引入应开发票明细</a>
					</li>
					<li class="payable"><a data-toggle="tab" href="#tab-2" aria-expanded="false">引入结算单明细</a>
					</li>
				</ul>
				<div class="tab-content">
					<div  id="tab-1" class="tab-pane active tableBox">
						<table id="contentTable" class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable contentTable1">
							<thead>
							<tr>
								<th> <input type="checkbox" class="i-checks"></th>
								<th  class="sort-column entityNo">发票号</th>
								<th  class="sort-column invoiceMoney">本次开票金额</th>
								<th  class="sort-column vcaMoney">已核销金额</th>
								<th  class="sort-column theVcaMoney">本次收款金额</th>
								<th  class="sort-column remarks">备注信息</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody id="detailTbody">
							<c:forEach items="${list}" var="feeBillDetail" >
								<input type="hidden" name="invoiceObj" id="invoiceObj" value="${feeBillDetail.feeOpenInvoice.invoiceObj}"/>
								<tr id="${feeBillDetail.feeOpenInvoice.id}">
									<td> <input type="checkbox" id="${feeBillDetail.id}" value="${feeBillDetail.id}" class="i-checks"></td>
									<td><%--发票号(实体票号)--%>
										<c:if test="${sign eq 'invoice'}">
											<a  href="#" onclick="jp.openDialogView('查看应开发票明细', '${ctx}/fee/openInvoice/form?different=billPage&id=${feeBillDetail.feeOpenInvoice.id}','800px', '500px')">
													${feeBillDetail.feeOpenInvoice.entityNo}
											</a>
										</c:if>
										<c:if test="${flag eq 'feeBill'}">
											<a  href="#" onclick="jp.openDialogView('查看应开发票明细', '${ctx}/fee/openInvoice/form?different=billPage&id=${feeBillDetail.feeOpenInvoice.id}','950px', '500px')">
													${feeBillDetail.invoiceNo}
											</a>
										</c:if>
									</td>
									<td  id="${feeBillDetail.feeOpenInvoice.id}_${feeBillDetail.id}_invoiceMoney">
											<%--开票金额--%>
										<c:if test="${sign eq 'invoice'}">
											<fmt:formatNumber value="${feeBillDetail.invMoney}" pattern="#.00"/>
										</c:if>
										<c:if test="${flag eq 'feeBill'}">
											<fmt:formatNumber value="${feeBillDetail.invoiceMoney}" pattern="#.00"/>
										</c:if>
									</td>
									<td  id="${feeBillDetail.feeOpenInvoice.id}_${feeBillDetail.id}_vcaMoney">
										<c:if test="${feeBillDetail.vcaMoney ne null and feeBillDetail.vcaMoney > 0}">
											<fmt:formatNumber value="${feeBillDetail.vcaMoney}" pattern="#.00"/>
										</c:if>
									</td>
									<td class="coun" name="${feeBillDetail.feeOpenInvoice.id}_${feeBillDetail.id}">
											<%--本次核销金额--%>
										<c:if test="${flag eq 'feeBill'}">
											<input type="text" id="${feeBillDetail.feeOpenInvoice.id}_${feeBillDetail.id}_theVcaMoney" disabled="disabled"
												   value="${feeBillDetail.theVcaMoney}"  style="border:none;background:#FFFFFF" />
										</c:if>
										<c:if test="${sign eq 'invoice'}">	<%--发票id，发票子表id 本次核销金额--%>
											<input type="text" id="${feeBillDetail.feeOpenInvoice.id}_${feeBillDetail.id}_theVcaMoney"
												   style="border:none;background:#FFFFFF" onchange="inputBlur()" class="form-control  number" />
										</c:if>
									</td>
									<td>
											<%-- ${feeBillDetail.remarks} --%>
											<%--备注--%>
										<c:if test="${sign eq 'invoice'}">
											${feeBillDetail.feeOpenInvoice.remarks}
										</c:if>
										<c:if test="${flag eq 'feeBill'}">
											${feeBillDetail.remarks}
										</c:if>
									</td>
									<td>
											<c:if test="${sign eq 'invoice'}">
												<a href="#" onclick="jp.openDialogView('查看应开发票明细', '${ctx}/fee/openInvoice/form?different=billPage&id=${feeBillDetail.feeOpenInvoice.id}','800px', '500px')" class="btn btn-info btn-xs" ><i class="fa fa-search-plus"></i> 查看</a>
											</c:if>
											<c:if test="${flag eq 'feeBill'}">
												<a href="#" onclick="jp.openDialogView('查看应开发票明细', '${ctx}/fee/openInvoice/form?different=billPage&id=${feeBillDetail.feeOpenInvoice.id}','950px', '500px')" class="btn btn-info btn-xs" ><i class="fa fa-search-plus"></i> 查看</a>
											</c:if>
										<c:if test="${bill.id eq null}">
											<input type="button" onclick="deleteInPage('${feeBillDetail.feeOpenInvoice.id}','${feeBillDetail.feeOpenInvoice.id}_${feeBillDetail.id}')" value="删除"  class="btn btn-danger btn-xs">
										</c:if>
										<c:if test="${bill.id ne null and bill.status eq 0}">
											<input type="button" onclick="deletes('${feeBillDetail.id}')" value="删除"  class="btn btn-danger btn-xs">
										</c:if>
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
					</div>
					<!-- 结算单明细表 -->

					<!-- 表格 -->
					<div id="tab-2" class="tab-pane tableBox">
						<table id="contentTable_payable" class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable">
							<thead>
							<tr>
								<th> <input type="checkbox" class="i-checks"></th>
								<th>结算单号</th>
								<th>结算日期</th>
								<th>结算方</th>
								<th>结算金额</th>
								<th>已核销金额</th>
								<th>本次收款金额</th>
								<th>备注信息</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody id="payableDetailTbody">
							<c:forEach items="${billReceiveDetails}" var="billReceiveDetails" >
								<%--结算方--%>
								<input type="hidden" name="feePayableName" id="feePayableName"
									   value="${details.feePayable.payee}"/>
								<tr id="${billReceiveDetails.id}">
									<td> <input type="checkbox" id="${billReceiveDetails.id}" value="${billReceiveDetails.id}" class="i-checks"></td>
									<td>
											${billReceiveDetails.clearingNo}
									</td>
									<td>
												<fmt:formatDate value="${billReceiveDetails.busyDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
									</td>
									<td>
											${billReceiveDetails.feeConsignor.name}
									</td>
									<td id="${billReceiveDetails.id}_invoiceMoney">
										<fmt:formatNumber value="${billReceiveDetails.clearingMoney}" pattern="#.00"/>
									</td>
									<td id="${billReceiveDetails.id}_vcaMoney">
										<c:if test="${billReceiveDetails.vcaMoney ne null and billReceiveDetails.vcaMoney > 0}">
											<fmt:formatNumber value="${billReceiveDetails.vcaMoney}" pattern="#.00"/>
										</c:if>
									</td>
									<td class="coun" name="${billReceiveDetails.id}">
										<c:if test="${sign eq 'sign'}">
											<input type="text" id="${billReceiveDetails.id}_theVcaMoney" disabled="disabled"
												   value="${billReceiveDetails.theVcaMoney}" class="form-control required" style="width:200px;"/>
										</c:if>
										<c:if test="${flag eq 'payable'}">
											<input type="text" id="${billReceiveDetails.id}_theVcaMoney"
												   onchange="inputBlurPayable()" value="" class="form-control required" style="width:200px;"/>
										</c:if>
									</td>
									<td>
											${billReceiveDetails.remarks}
									</td>
									<td>
										<a href="#" onclick="jp.openDialogView('查看应收结算单明细', '${ctx}/fee/receivables/form?different=invoicePage&id=${billReceiveDetails.feeReceivables.id}','800px', '500px')" class="btn btn-info btn-xs" ><i class="fa fa-search-plus"></i> 查看</a>
										<c:if test="${bill.id ne null and bill.status eq 0}">
											<input type="button" onclick="deleteFeeBillReceDetail('${billReceiveDetails.id}')" value="删除"
												   class="btn btn-danger btn-xs">
										</c:if>

									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
					</div>

				</div>
			</div>

		<c:if test="${fns:hasPermission('fee:bill:edit') || isAdd}">
				<div class="col-lg-3"></div>
		        <div class="col-lg-6">
		             <div class="form-group text-center">
		                 <div>
		                     <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
		                 </div>
		             </div>
		        </div>
		</c:if>
		</form:form>
		</div>				
	</div>
	</div>
</div>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 750px">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">应开发票列表</h4>
			</div>
			<div class="modal-body">
				<!-- 查询条件 -->
				<div class="row">
					<div class="col-sm-12">
						<form action="" method="post" class="form-inline" id="searchForm">
							<div class="form-group pull-left">
								<span>结算方：</span>
								<input value="" type="text" name="balance" id="balance" title="" class="form-control input-sm"/>
							</div>
						</form>
						<div class="pull-right">
							<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="searchDetail()" ><i class="fa fa-search"></i> 查询</button>
							<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="reset()" ><i class="fa fa-refresh"></i> 重置</button>
						</div>
					</div>
				</div>
				<!-- 表格 -->
				<div  class="table-box1">
					<table id="content" class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable tableAjax">
						<thead>
						<tr>
							<th> <input type="checkbox" class="checkbox_css" id="allCheckBox" name="all"></th>
							<th  class="sort-column status">状态</th>
							<th  class="sort-column invoiceNo">发票单号</th>
							<th  class="sort-column invoiceDate">开票日期</th>
							<th  class="sort-column invoiceObj">结算方</th>
							<th  class="sort-column invoiceMoney">开票金额</th>
							<th  class="sort-column remarks">备注信息</th>
						</tr>
						</thead>
						<tbody id="openInvoiceDetailLists">
						</tbody>
					</table>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" onclick="detail()">确定</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
<!-- 引入结算单模态框（Modal） -->
<div class="modal fade" id="modal_payable" tabindex="-1" role="dialog" aria-labelledby="title_payable" aria-hidden="true">
	<div class="modal-dialog" style="width: 750px">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="title_payable">应收结算单列表</h4>
			</div>
			<div class="modal-body">
				<!-- 查询条件 -->
				<div class="row">
					<div class="col-sm-12">
						<form action="" method="post" class="form-inline searchForm" id="">
							<div class="form-group pull-left">
								<span>结算方：</span>
								<input value="" type="text" name="balance_payable" id="balance_payable" title="" class="form-control input-sm"/>
							</div>
						</form>
						<div class="pull-right">
							<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="searchReceDetail()" ><i class="fa fa-search"></i> 查询</button>
							<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="resetRece()" ><i class="fa fa-refresh"></i> 重置</button>
						</div>
					</div>
				</div>
				<!-- 表格 -->
				<div  class="table-box1">
					<table id="content_payable" class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable tableAjax_payable">
						<thead>
						<tr>
							<th> <input type="checkbox" class="checkbox_css" id="all_payable" name="all"></th>
							<th  class="sort-column status">状态</th>
							<th  class="sort-column clearingNo">结算单号</th>
							<th  class="sort-column busyDate">结算日期</th>
							<th  class="sort-column payee">结算方</th>
							<th  class="sort-column clearingMoney">结算金额</th>
							<th  class="sort-column remarks">备注信息</th>
						</tr>
						</thead>
						<tbody id="receiveLists">
						</tbody>
					</table>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" onclick="sure_payable()" >确定</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
</body>
</html>